package applet.molecule;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.Canvas3D;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class CanvasPanel extends JPanel {

	private Canvas3D canvas;
	
	private int canvasSize;
	
	private boolean isGroup;
	
	public CanvasPanel(GraphicsConfiguration config, int panelSize, boolean isGroup){
		this.isGroup = isGroup;
		
		canvas = new Canvas3D(config);
		
		canvasSize = panelSize - 13;
		
		canvas.setSize(canvasSize, canvasSize);
		add(canvas);
		canvas.setLocation(0, 13);

		if (!MoleculeNet.isGroup) {
			setBorder(javax.swing.BorderFactory
					.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		}
	}
	
	public Canvas3D getCanvas(){
		return canvas;
	}

	public void paint(Graphics g) {
		super.paint(g);
		
		if(isGroup){
			final int rectSize = canvasSize;

			g.setColor(Color.BLACK);
			// outer
			g.drawLine(14, 2, 14, 0);
			g.drawLine(14, 0, rectSize + 12, 0);
			g.drawLine(rectSize + 12, 0, rectSize + 12, rectSize - 2);
			g.drawLine(rectSize + 12, rectSize - 2, rectSize + 9, rectSize - 2);

			// internal
			g.drawLine(10, 5, 10, 2);
			g.drawLine(10, 2, rectSize + 9, 2);
			g.drawLine(rectSize + 9, 2, rectSize + 9, rectSize);
			g.drawLine(rectSize + 9, rectSize, rectSize + 6, rectSize);
		}
	}
}
